/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package carrello.impl.boundary.administrator;

import carrello.exception.CarrelloException;
import carrello.impl.boundary.AbstractUI;
import carrello.impl.controller.administrator.UpdateProductCTRL;
import carrello.impl.controller.user.ProductCTRL;
import carrello.model.entities.Product;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Usman
 */
public class UpdateProductUI extends AbstractUI{
    private LinkedList<LinkedList<String>> attributes;
    private String[] values;
    private int numOfExtraInfo;
    private int productid;
    private Product product;
    private List productExtraInfo;
    private int cancelled;
    private String error;
    
    public void setcancelled ( int c ) {
        cancelled = c;
    }
    public void setproductExtraInfo (List p) {
        productExtraInfo = p;
    }
    public List getproductExtraInfo () {
        return productExtraInfo;
    }
    public void setproductid ( int c ) {
        productid = c;
    }
    public int getProductid () {
        return productid;
    }
    public LinkedList<LinkedList<String>> getAttributes () {
        return attributes;
    }
    
    public void setValues (String[] atts ) {
        values = atts;
    }
    public Product getProduct () {
        return product;
    }
    public int getnumOfExtraInfo () {
        return numOfExtraInfo;
    }
    @Override
    public String execute () 
    {
        try {
            if ( attributes == null && values == null ) {
                attributes = UpdateProductCTRL.getAllAttributeValues (productid);
                return INPUT;
            }
            else if ( cancelled == 0 ) {
                UpdateProductCTRL.updateAttributeValues ( values, productid );
            }

            product = ProductCTRL.getProductById(productid);
            productExtraInfo = ProductCTRL.getProductInfoById(productid);
            numOfExtraInfo = productExtraInfo.size();
            return SUCCESS;
        } catch (CarrelloException ex) {
            seterror (ex.getMessage());
            Logger.getLogger(UpdateProductUI.class.getName()).log(Level.SEVERE, null, ex);
            return ERROR;
        }
    }

    public String geterror () {
        return error;
    }
    public void seterror(String message) {
        error = message;
    }
}
